<template>
	<view class="content" style='background-color: #efefef;'>
		<!-- 报名字段 -->
		<div v-for="(item,index) in entryForm" :key='item.index'>
			<view class="row b-b" style='font-size: 14px;'>
				<text class="tit" style='font-size: 17px;'>{{item.name}}</text>
				<input class="input" type="text" v-model="ceshi[index]" placeholder="请输入内容"
					placeholder-class="placeholder" />
			</view>
		</div>
		<!-- 弹出框 -->
		<van-dialog id="van-dialog" />
		<!-- 转订单 -->
		<div style="margin: 16px;">
			<van-button @click="toOrder(e)" round block type="primary">
				下一步
			</van-button>
		</div>
	</view>
</template>

<script>
	import Dialog from "../../static/vant/dist/dialog/dialog"
	import Vue from 'vue'
	export default {
		data() {
			return {
				ceshi: [],
				activity: {
					address: '',
					beginTime: '',
					context: '',
					createTime: '',
					creator: '',
					endTime: '',
					expire: '',
					headline: '',
					id: '',
					label: '',
					peopleNum: '',
					plate: '',
					poster: "poster_delb9",
					publisherId: '',
					recommend: '',
					spotlight: '',
					type: '',
					updateTime: '',
					updater: ''
				},
				form: {
					activityId: '',
					userId: '',
					ticketId: '',
					ticketNum: ''
				},
				entryForm: [],
				formKeyArr: [],
				submit: {},
				content: 0,
			}
		},
		onLoad: function(option) {
			var options = JSON.parse(decodeURIComponent(option.activity))
			var form = JSON.parse(decodeURIComponent(option.form))
			this.activity = options
			this.form = form
			console.log(options)
			this.findActivityData()
		},
		mounted() {
		},
		created() {},
		methods: {
			// 转订单页面
			toOrder(e) {
				this.content = 0
				this.submit = {}
				this.entryForm.forEach((item, index) => {
					// aa[item.field] = this.ceshi[index]
					if (this.ceshi[index] != null) {
						this.content++
						this.$set(this.submit, item.field, this.ceshi[index])
					} else {
						this.deleteAttribute()
						Dialog.alert({
							message: '请选择门票',
						}).then(() => {
							this.content = 0
						});

					}
				})
				if (this.content != this.entryForm.length) {
					this.content = 0
					this.deleteAttribute()
					Dialog.alert({
						message: '请填写数据',
					}).then(() => {
						// on close
					});
				} else {
					this.$set(this.submit, "activityId", this.form.activityId)
					this.$set(this.submit, "userId", this.form.userId)
					this.$set(this.submit, "ticket", this.form.ticketId)
					this.$set(this.submit, "ticketnum", this.form.ticketNum)
					uni.request({
						url: 'http://localhost:8085/partActivite/addOne',
						method: "post",
						data: this.submit,
						success: (res) => {}
					})
					uni.navigateTo({
						url: "/pages/order/pay?applicationForm=" + encodeURIComponent(JSON.stringify(this
							.submit)),
					})
				}
			},
			// 重置输入框
			deleteAttribute() {
				var attribute = []
				this.entryForm.forEach((item, index) => {
					attribute.push(item.field)
				});
				console.log(attribute)
				for (var a = 0; a < attribute.length; a++) {
					// this.$delete(this.submit, 'email')
					// Vue.delete(this.submit, 'telephony')
					this.$delete(this.ceshi, '0')
					Vue.delete(this.ceshi, '1')
				}
			},
			// 查报名字段
			findActivityData(e) {
				uni.request({
					url: 'http://localhost:8083/entryForm/' + this.activity.id,
					method: "GET",
					success: (res) => {
						console.log(res);
						this.entryForm = res.data.data
					}
				})
			},
			// findApplicationForm(e) {
			// 	uni.request({
			// 		url: 'http://localhost:8085/activity/' + this.activityId,
			// 		method: "GET",
			// 		success: (res) => {
			// 			console.log(res);
			// 			this.activity = res.data.data
			// 		}
			// 	})
			// },
		}
	}
</script>

<style lang="scss">
	page {
		padding-top: 16upx;
	}

	.row {
		// display: flex;
		// align-items: center;
		position: relative;
		padding: 0 30upx;
		height: 110upx;
		background: #fff;

		.tit {
			flex-shrink: 0;
			width: 120upx;
			font-size: 30upx;

		}

		.input {
			flex: 1;
			font-size: 30upx;

		}

		.icon-shouhuodizhi {
			font-size: 36upx;

		}
	}

	.add-btn {
		width: 690upx;
		height: 80upx;
		margin: 60upx auto;
		background-color: rgb(28, 42, 134);
		color: #fff;

		border-radius: 10upx;
		box-shadow: 1px 2px 5px rgba(28, 42, 134, 0.4);
	}
